
from fastapi import APIRouter
from typing import Optional
from pydantic import BaseModel

# setting
from settings.settings import settings
# agv socket 工厂方法
from sockets.agvsocket import AgvSocket

agv_so_manage = AgvSocket()


# 创建status router路由
control_router = APIRouter()



class StatusParams(BaseModel):
    msg_type: int
    msg: Optional[dict]

    class Config:
        schema_extra = {
            "example": {
                "msg_type": 1000,
                "msg": {"参数名称": "xx参数"}
            }
        }


@control_router.get("/", response_description="编号 查询结果")
async def get_control():
    agv_control_socket = agv_socket_factory.get(Port.CONTROL.value)
    return "地图"


@control_router.post("/", response_description="编号 查询结果")
async def post_control(params: StatusParams):
    agv_control_socket = agv_socket_factory.get(Port.CONTROL.value)
    print(params)
    return {
        "map": '地图'
    }
    # try:
    #     agv_socket.send(1,Status(params.msg_type).value,{})
    #     res = agv_socket.receive()
    #     return res
    # except Exception as e:
    #     print(e)
    #     raise HTTPException(
    #         status_code=409,
    #         detail="查询编号不正确"
    #     )
